//
//  CommonSubViewController.swift
//  DataStructuresAlgorithms
//
//  Created by xiangzuhua on 2021/3/15.
//

import UIKit

class CommonSubViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    var tableView: UITableView?
    var data: Array<String>?
    var titleName: String?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = titleName
        self.queryData(titleName)
    
        tableView = UITableView(frame: self.view.bounds, style: .plain)
        tableView?.delegate = self
        tableView?.dataSource = self
        self.view.addSubview(tableView!)
        tableView?.tableFooterView = UIView(frame: CGRect.zero)
        
        // Do any additional setup after loading the view.
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        data?.count ?? 0
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "CommonSubCell")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "CommonSubCell")
        }
        cell!.textLabel!.text = data?[indexPath.row]
        cell!.accessoryType = .disclosureIndicator
        
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let detailVC = DetailViewController()
        detailVC.name = data?[indexPath.row]
        self.navigationController?.pushViewController(detailVC, animated: true)
    }
    
    func queryData(_ type: String?) {
        switch type {
        case ArrayModule:
            data = ["无"]
        case LinkListModule:
            data = [LinkListReversal, LinkListCycleDetection, LinkListsMerge, LinkListDeletLastN, LinkListMiddle]
        case StackModule:
            data = ["无"]
        case QueueModule:
            data = ["无"]
        case SortModule:
            data = ["无"]
        case GraphModule:
            data = [GraphBreadthFirst, GraphDepthFirst, GraphTopoSortKahn, GraphTopoSortDFS]
        default:
            data = ["无"]
            
        }
    }
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
